package com.bw.journal.insert

import androidx.lifecycle.viewModelScope
import com.bw.common.mvi.BaseViewModel
import com.bw.journal.insert.entity.JournalInsertState
import kotlinx.coroutines.launch

class JournalInsertViewModel : BaseViewModel<JournalInsertRepo,JournalInsertState>() {
    override fun createRepo(): JournalInsertRepo {
        return JournalInsertRepo()
    }

    override fun createState(): JournalInsertState {
        return JournalInsertState(false)
    }

    fun insert(map:Map<String,Any>){
        viewModelScope.launch {
            subFlow(repo.requestInsert(map))
                .collect{
                    if (it.statusCode == 200){
                        mutableContainer.updateUiState { copy(true) }
                    }
                }
        }
    }

}